home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Information / CSMP Digest / volume 1 / csmp-v1-192.txt < prev    next >
Text File  |  1992-12-31  |  44KB  |  1,248 lines

  1. C.S.M.P. Digest             Tue, 20 Oct 92       Volume 1 : Issue 192
  2.  
  3. Today's Topics:
  4.  
  5.     Trap intercepts
  6.     Apple Events
  7.     Porting code using fork() to the Mac
  8.     DESPERATE: switching pixmaps w/ SetPortPix
  9.  
  10.  
  11.  
  12. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  13.  
  14. The digest is a collection of article threads from the internet newsgroup
  15. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  16. regularly and want an archive of the discussions.  If you don't know what a
  17. newsgroup is, you probably don't have access to it.  Ask your systems
  18. administrator(s) for details.  (This means you can't post questions to the
  19. digest.)
  20.  
  21. Each issue of the digest contains one or more sets of articles (called
  22. threads), with each set corresponding to a 'discussion' of a particular
  23. subject.  The articles are not edited; all articles included in this digest
  24. are in their original posted form (as received by our news server at
  25. cs.uoregon.edu).  Article threads are not added to the digest until the last
  26. article added to the thread is at least one month old (this is to ensure that
  27. the thread is dead before adding it to the digest).  Article threads that
  28. consist of only one message are generally not included in the digest.
  29.  
  30. The entire digest is available for anonymous ftp from ftp.cs.uoregon.edu
  31. [128.223.8.8] in the directory /pub/mac/csmp-digest.  Be sure to read the
  32. file /pub/mac/csmp-digest/README before downloading any files.  The most
  33. recent issues are available from sumex-aim.stanford.edu [36.44.0.6] in the
  34. directory /info-mac/digest/csmp.  If you don't have ftp capability, the sumex
  35. archive has a mail server; send a message with the text '$MACarch help' (no
  36. quotes) to LISTSERV@ricevm1.rice.edu for more information.
  37.  
  38. The digest is also available via email.  Just send a note saying that you
  39. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  40. automatically receive each new issue as it is created.  Sorry, back issues
  41. are not available through the mailing list.
  42.  
  43. Send administrative mail to mkelly@cs.uoregon.edu.
  44.  
  45.  
  46. -------------------------------------------------------
  47.  
  48. From: George.Economou@f120.n129.z1.FIDONET.ORG (George Economou)
  49. Subject: Trap intercepts
  50. Date: Wed, 05 Aug 92 17:27:10 EST
  51. Organization: FidoNet node 1:129/120 - Mac For The Mind, Pittsburgh PA
  52.  
  53. I am trying to write a trap intercept for waitnextevent.  It is contained in
  54. an INIT.  The init loads fine and does not crash the system, but it doesn't do
  55. what I installed.  Can anyone give me some help via source or other info?
  56. I followed the way they said to do it in MAcintosh Prog. Secrets 2nd edition.
  57.  
  58. George Economou
  59.  
  60. - --  
  61. George Economou via cmhGate - Net 226 fido<=>uucp gateway Col, OH
  62. UUCP: ...!n8emr!bluemoon!cmhgate!129!120!George.Economou
  63. INET: George.Economou@f120.n129.z1.FIDONET.ORG
  64.  
  65. +++++++++++++++++++++++++++
  66.  
  67. From: keith@taligent.com (Keith Rollin)
  68. Date: 10 Aug 92 19:11:37 GMT
  69. Organization: Taligent
  70.  
  71. In article <936620.2A85E472@cmhgate.fidonet.org>,
  72. George.Economou@f120.n129.z1.FIDONET.ORG (George Economou) writes:
  73. > I am trying to write a trap intercept for waitnextevent.  It is contained in
  74. > an INIT.  The init loads fine and does not crash the system, but it doesn't do
  75. > what I installed.  Can anyone give me some help via source or other info?
  76. > I followed the way they said to do it in MAcintosh Prog. Secrets 2nd edition.
  77.  
  78. Hmmm...then I guess I'd better answer this...
  79.  
  80. Sorry to lead you astray, George, but I guess we didn't cover all the pitfalls
  81. of patching traps. There are some considerations you have to make with certain
  82. traps. WaitNextEvent is one of them.
  83.  
  84. The problem is that there are three "kinds" of traps in the Macintosh. Those
  85. that are in ROM, those that are implemented early in the Mac's startup sequence
  86. (before INIT time), and those that are implemented late in the startup sequence
  87. (after INIT).
  88.  
  89. WaitNextEvent belongs to this third category. What happens is this. The Mac
  90. starts up. It sets some things up, and then runs the INITs. Your INIT runs and
  91. patches WaitNextEvent. Later, the third category of traps are implemented,
  92. wiping out your patch in the process.
  93.  
  94. There are three things you can do to get around this. In general, what people do
  95. is patch a different trap instead that _won't_ get wiped out to. This second
  96. patch is responsible for patching the trap you really want at a time that's
  97. safe.
  98.  
  99. Another thing you can do is patch SetTrapAddress to protect your patch. Write
  100. your SetTrapAddress patch to detect when someone tries to over patch your patch.
  101. If it detects that, keep your patch address in the trap table, and store the new
  102. patch address locally. You'll also need to patch GetTrapAddress to return this
  103. local copy if it's asked for.
  104.  
  105. In your case, you have an easier alternative. Hook into the low-memory global
  106. jGNEFilter. This is a hook that's called just before Get/WaitNextEvent returns
  107. to the caller. Be sure to save all registers, and be sure to chain to any
  108. routines already hooked into jGNEFilter. There's a technote on this that you can
  109. peruse.
  110.  
  111. Hope this helps,
  112.  
  113. - --
  114. Keith Rollin
  115. Phantom Programmer
  116. Taligent, Inc.
  117.  
  118. +++++++++++++++++++++++++++
  119.  
  120. From: volaski@acsu.buffalo.edu (Maurice Volaski)
  121. Date: 11 Aug 92 14:34:11 GMT
  122. Organization: UB
  123.  
  124. In article <Bss7zE.26D@taligent.com> keith@taligent.com (Keith Rollin) writes:
  125. >In your case, you have an easier alternative. Hook into the low-memory global
  126. >jGNEFilter. This is a hook that's called just before Get/WaitNextEvent returns
  127. >to the caller. Be sure to save all registers, and be sure to chain to any
  128. >routines already hooked into jGNEFilter. There's a technote on this that you can
  129. >peruse.
  130.  
  131. There is more...If you want to *modify* the event, then this won't do because
  132. desk accessories get the event before the jGNEFilter. In this case, you would
  133. have to patch SystemEvent, and then that has problems too. Some programs 
  134. disable it and others don't even call WaitNextEvent all the time. You could
  135. conceivably be left with having to tail-patch OSEventAvail and GetOSEvent :-(
  136.  
  137. Maurice Volaski
  138.  
  139. ---------------------------
  140.  
  141. From: francois@welchgate.welch.jhu.edu (Francois Schiettecatte)
  142. Subject: Apple Events
  143. Organization: Johns Hopkins Univ. Welch Medical Library
  144. Date: Tue, 16 Jun 1992 18:17:36 GMT
  145.  
  146.  
  147. Hi
  148.  
  149. When  an application receives an Apple Event how can 
  150. it uniquely identify the process/machine
  151. that sent it. I am sure that this information
  152. is available in the AE but I have not found out
  153. how to get it out of there.
  154.  
  155.  
  156. francois
  157.  
  158. Francois Schiettecatte
  159. Software Engineer
  160. Welch Medical Library
  161. Johns Hopkins University
  162. Internet: francois@library.welch.jhu.edu
  163. Phone    : (410) 955-7581
  164.  
  165.  
  166. +++++++++++++++++++++++++++
  167.  
  168. From: kamprath@caen.engin.umich.edu (Michael F. Kamprath)
  169. Date: Sat, 11 Jul 92 14:50:39 EDT
  170. Organization: University of MIchigan
  171.  
  172. For the longest time, I thought something was wrong with my program when I 
  173. would get an noOutstandingHLE error when ever I would want to proccess an
  174. Apple Event.  But, I then turned off the debugger on THINK C 5, and low and
  175. behold, my program no longer had troubles.  
  176.  
  177. So, why can't my program (actually, project) receive high level events when
  178. I am also using the THINK C Debugger?  Is this a bug in the debugger, or
  179. am I doing something wrong?
  180.  
  181. Michael Kamprath
  182. kamprath@caen.engin.umich.edu
  183.  
  184.  
  185. +++++++++++++++++++++++++++
  186.  
  187. From: gwatts@cdf34.fnal.gov (Gordon Watts -- U of Rochester)
  188. Organization: Fermilab
  189. Date: Tue, 14 Jul 1992 15:11:15 GMT
  190.  
  191. In article <xCM-SG+@engin.umich.edu>, kamprath@caen.engin.umich.edu (Michael F. Kamprath) writes...
  192. >For the longest time, I thought something was wrong with my program when I 
  193. >would get an noOutstandingHLE error when ever I would want to proccess an
  194. >Apple Event.  But, I then turned off the debugger on THINK C 5, and low and
  195. >behold, my program no longer had troubles.  
  196.  
  197. Hi,
  198.   When using Think C debugger with AEs, I've found two things of use.  First,
  199. think doesn't preserve (when running the debugger) the creator id, so address
  200. made with the application's signature won't work right.  I stumbled on this
  201. when using self-aes, but you may also have this problem.  I've been using
  202. process ids for a while now, and that all seems to work.
  203.  
  204.   Second thing has to do with time-outs.  Don't set a break in your event
  205. loop when sending aes.  If you do, and the apple event is sent with a
  206. timeout (2 seconds or something like that), by the time you hit "go" from
  207. the break point, 2 seconds have passed and the apple event is unqueued.  Break
  208. points in the handlers are fine.  Or, I guess, you could put an infinite
  209. timeout on your AESend call.
  210.  
  211.     Cheers,
  212.  
  213.         Gordon.
  214.  
  215.  
  216. +++++++++++++++++++++++++++
  217.  
  218. From: mxmora@unix.sri.com (Matthew Xavier Mora)
  219. Date: 14 Jul 92 16:58:37 GMT
  220. Organization: SRI International
  221.  
  222. I want my CD player program to be scriptable and to support
  223. appleEvents. I did a quick browse of the Apple event registry
  224. and did not see anything I could use. Is there some kind of media
  225. event type that has been defined that I missed? I'm looking for event
  226. types like play, pause, stop, rewind, fast forward and QueToHere. You 
  227. would think that Apple has define something like this for Quicktime or for
  228. controlling movies or a video disk player.
  229.  
  230. Are there such apple events?
  231.  
  232. Thanks
  233.  
  234. Matt
  235.  
  236. +++++++++++++++++++++++++++
  237.  
  238. From: pete@aurora.rice.edu (Louis Wu)
  239. Organization: Whatsamatta U
  240. Date: Tue, 14 Jul 1992 20:58:32 GMT
  241.  
  242. In article <14JUL92091115@cdf34.fnal.gov> gwatts@cdf34.fnal.gov (Gordon Watts -- U of Rochester) writes:
  243.  
  244.    In article <xCM-SG+@engin.umich.edu>, kamprath@caen.engin.umich.edu (Michael F. Kamprath) writes...
  245.    >For the longest time, I thought something was wrong with my program when I 
  246.    >would get an noOutstandingHLE error when ever I would want to proccess an
  247.    >Apple Event.  But, I then turned off the debugger on THINK C 5, and low and
  248.    >behold, my program no longer had troubles.  
  249.    > 
  250.  
  251.    Hi,
  252.      When using Think C debugger with AEs, I've found two things of use.  First,
  253.    think doesn't preserve (when running the debugger) the creator id, so address
  254.    made with the application's signature won't work right.  I stumbled on this
  255.    when using self-aes, but you may also have this problem.  I've been using
  256.    process ids for a while now, and that all seems to work.
  257.  
  258. True, but you can still send apple events to the program being debugged by
  259. addressing the event to the name of your project.
  260.  
  261. - --
  262. =============================================================================
  263. Pete Keleher   "Relax! Don't worry! Have a homebrew!"        pete@cs.rice.edu
  264. =============================================================================
  265.  
  266.  
  267. +++++++++++++++++++++++++++
  268.  
  269. From: leonardr@ccs.itd.umich.edu
  270. Organization: Campus Computing Sites, University of Michigan-Ann Arbor
  271. Date: Wed, 15 Jul 92 01:47:57 GMT
  272.  
  273. In article <mxmora-140792095215@css-mac1.sri.com> mxmora@unix.sri.com (Matthew Xavier Mora) writes:
  274. >I want my CD player program to be scriptable and to support
  275. >appleEvents. I did a quick browse of the Apple event registry
  276. >and did not see anything I could use. Is there some kind of media
  277. >event type that has been defined that I missed? I'm looking for event
  278. >types like play, pause, stop, rewind, fast forward and QueToHere. You 
  279. >would think that Apple has define something like this for Quicktime or for
  280. >controlling movies or a video disk player.
  281. >
  282. >Are there such apple events?
  283. >
  284.     Last time I checked with John Pugh (kAERegistrar) they had not yet
  285. developed a Quicktime suite, or a "media" suite.  You might want to check a
  286. again (or John could chime in ;).  
  287.  
  288.     If you don't want to wait for the folks at Apple, you might want to
  289. develop your own custom events for the first version of your software and
  290. then update in the future with the "standard" events.
  291.  
  292. - -- 
  293. - -----------------------------------------------------------------------
  294. Leonard Rosenthol          Internet: leonardr@ccs.itd.umich.edu
  295. Director of Advanced Technology   AppleLink: MACgician
  296. Aladdin Systems, inc.          GEnie:     MACgician
  297.  
  298. +++++++++++++++++++++++++++
  299.  
  300. From: eric_gorr@coglab_psych.uoregon.edu (Eric Gorr)
  301. Organization: University of Oregon Network Services
  302. Date: Wed, 22 Jul 92 20:44:11 GMT
  303.  
  304. I was wondering if someone could point me to or send me some sample code
  305. which demonstrates how to implement some application-specific events.
  306.  
  307. Basically what I am doing is writing an application that I would like to be
  308. able to run via apple-events.
  309.  
  310. (I would prefer the code be a complete (simple) application...)
  311.  
  312. thanx...
  313.  
  314.  
  315. +++++++++++++++++++++++++++
  316.  
  317. From: jpugh@apple.com (Jon Pugh)
  318. Date: 19 Jul 92 00:26:30 GMT
  319. Organization: Apple Computer, Inc.
  320.  
  321. In article <mxmora-140792095215@css-mac1.sri.com>, mxmora@unix.sri.com (Matthew Xavier Mora) writes:
  322. > I want my CD player program to be scriptable and to support
  323. > appleEvents. I did a quick browse of the Apple event registry
  324. > and did not see anything I could use. Is there some kind of media
  325. > event type that has been defined that I missed? I'm looking for event
  326. > types like play, pause, stop, rewind, fast forward and QueToHere. You 
  327. > would think that Apple has define something like this for Quicktime or for
  328. > controlling movies or a video disk player.
  329. > Are there such apple events?
  330.  
  331. There are no such events currently defined. Several people are interested
  332. in creating such events, but no one has taken the responsibility of doing it.
  333. Since all suites have to go through me to become offical, the first one to
  334. get something to me that will work will get it done their way (if I approve).
  335.  
  336. James "im" Beninghaus of DTS is going to be redoing his CD Remote to support
  337. AE soon.  You might want to collaborate with him to define some standards.
  338. We've been talking about some of the things that would be necessary.  His
  339. address is BENINGHAUS@Applelink.Apple.Com.  Tell him that I sent you.
  340.  
  341. Once an appropriate spec gets written and approved by me and some cohorts,
  342. we will post it on ftp.apple.com and Applelink.  New suites should also 
  343. appear on the Dev CDs as they are defined.
  344.  
  345. People are still climbing the learning for AE, but I am talking to more and
  346. more people who are doing things correctly.  It is very encouraging.  The
  347. time of Apple Events is approaching rapidly.
  348.  
  349. Jon Pugh
  350. kAERegistrar
  351.  
  352. +++++++++++++++++++++++++++
  353.  
  354. From: yjc@po.cwru.edu (Jerome Chan)
  355. Date: 30 Jul 92 17:37:43 GMT
  356. Organization: Alethea, The Twilight World!
  357.  
  358.  
  359.   I have just ftped down the Winter 92 Apple Events Registery and I am
  360. confused. What are Object Classes?
  361.  
  362. - ---
  363.  The Evil Tofu
  364.  
  365. "No Lah! Sure or not one? Dunno leh! Nebber Mind! Like that one!
  366. Terriblur Lah!"
  367.  
  368. +++++++++++++++++++++++++++
  369.  
  370. From: jpugh@apple.com (Jon Pugh)
  371. Date: 2 Aug 92 17:32:15 GMT
  372. Organization: Apple Computer, Inc.
  373.  
  374. In article <1992Jul30.173743.8571@usenet.ins.cwru.edu>, yjc@po.cwru.edu
  375. (Jerome Chan) wrote:
  376. >   I have just ftped down the Winter 92 Apple Events Registery and I am
  377. > confused. What are Object Classes?
  378.  
  379. As we have discussed in email, I will elucidate for the faceless masses.
  380.  
  381. For anyone interested in doing serious AppleEvent development using the 
  382. object model as described in the Apple Event Registry: Standard Suites,
  383. you should get a copy of the Developer CD and read the Collaborative
  384. Computing chapter of the New Inside Macintosh.  This rolls all the AE
  385. documentation into one place and makes it understandable (well, as 
  386. understandable as we can make it).
  387.  
  388. This new version of Inside Mac is coming slowly to stores near you.  It
  389. is well worth the cost of replacing your current IM.  Imagine all of QD 
  390. in one volume.  Imagine all the File Manager chapters rolled into one.
  391. Imagine all the Tech Notes eliminated because Inside Mac states all the
  392. necessary information.
  393.  
  394. Cool huh?
  395.  
  396. Jon
  397.  
  398. +++++++++++++++++++++++++++
  399.  
  400. From: MScott@FirstClass.COM (M. Scott Marcy)
  401. Date: 12 Aug 92 16:35:33 GMT
  402. Organization: First Class Systems, Inc.
  403.  
  404. Hi,
  405.  
  406. Well, I'm just adding support for AppleEvents to my program, and I need
  407. to reply to the open document event under certain circumstances (I can
  408. only open one document at a time). I want to send an error string back
  409. to the source application, so I followed the procedures in both Inside
  410. Mac VI (page 6-49, Listing 6-12) and AEObject-Edition Sample (in
  411. AppleEventCore.c). From all I can tell, I'm doing exactly the same
  412. thing, but my call to AEPutParamPtr/Desc returns an error -1704
  413. (errAENotAEDesc). I checked the reply record, which contains a 'null'
  414. descriptor. All the sample code shows that I should just call
  415. AEPutParamXXX to store my error string in the reply record--no other
  416. setup or initialization of the reply record is required.
  417.  
  418. What gives? I've looked everywhere I can think of on this one and
  419. haven't found any example other than adding the string directly to the
  420. reply event given to the event handler.
  421.  
  422. BTW: I've tried both AEPutParamPtr (as in the examples) and
  423. AEPutParamDesc, both with the same result. The code below has the
  424. AEPutParamDesc version.
  425.  
  426.  
  427. Scott Marcy
  428. First Class Systems, Inc.
  429. ALink:    FIRST.CLASS
  430. InterNET: MScott@FirstClass.COM            (Preferred)
  431.  
  432. ==========================================================================
  433.  
  434. Here's the code from my open document handler. The CHECK, FAIL,
  435. ERR_HANDLER stuff is for collecting and handling errors. Everything else
  436. should be (relatively) standard.
  437.  
  438. pascal OSErr miae_open_doc(AppleEvent *event, AppleEvent *reply, long ref)
  439. { ERR_HEADER
  440. #pragma unused (ref)
  441. Boolean            empty, have_list = FALSE, have_desc = FALSE;
  442. AEDescList        doc_list;
  443. AEDesc            desc;
  444. AEKeyword        keyword;        /* ignored */
  445. DescType        type;            /* ignored */
  446. Size            size;            /* ignored */
  447. long            num_items;
  448. FSSpec            file_spec;
  449. Str255            err_str;
  450. Str63            name;
  451. short            wd;
  452.  
  453.     /* Get the required parameters */
  454.     CHECK(AEGetParamDesc(event, keyDirectObject, typeAEList, &doc_list));
  455.     have_list = TRUE;
  456.  
  457.     /* Make sure there are no more required parameters */
  458.     CHECK(miae_got_all_params(event, &empty));
  459.     if (!empty)
  460.         FAIL(errAEEventNotHandled);
  461.  
  462.     /* Count the number of files sent to us */
  463.     CHECK(AECountItems(&doc_list, &num_items));
  464.  
  465.     /* We can only open one document, otherwise return an error */
  466.     if (num_items > 1) {
  467.         /* Get an error string */
  468.         GetIndString(err_str, rErrorStrings, iMultOpenErr);
  469.         CHECK(AECreateDesc(typeChar, (Ptr) &err_str[1], err_str[0], &desc));
  470.         have_desc = TRUE;
  471.         CHECK(AEPutParamDesc(reply, keyErrorString, &desc));
  472.         CHECK(AEDisposeDesc(&desc)); have_desc = FALSE;
  473.         FAIL(errAEEventNotHandled); }
  474.     else if (num_items == 1) {
  475.         /* Open the one database specified */
  476.         CHECK(AEGetNthPtr(&doc_list, 1, typeFSS, &keyword, &type,
  477.                         (Ptr) &file_spec, sizeof(file_spec), &size));
  478.         /* Make a working directory reference for our open routine */
  479.         CHECK(OpenWD(file_spec.vRefNum, file_spec.parID, FCGB_CREATOR, &wd));
  480.         p_to_c_string(file_spec.name, name);
  481.         CHECK(mi_open_database(wd, name, FALSE));
  482.         CHECK(CloseWD(wd)); }
  483.  
  484.     /* Release the document list handle */
  485.     CHECK(AEDisposeDesc(&doc_list)); have_list = FALSE;
  486.  
  487. ERR_HANDLER
  488.     if (have_list)
  489.         AEDisposeDesc(&doc_list);
  490.     if (have_desc)
  491.         AEDisposeDesc(&desc);
  492. ERR_HANDLER_END
  493. } /* End: miae_open_doc */
  494.  
  495. +++++++++++++++++++++++++++
  496.  
  497. From: lai@Apple.COM (Ed Lai)
  498. Date: 12 Aug 92 20:04:44 GMT
  499. Organization: Apple Computer Inc., Cupertino, CA
  500.  
  501. The reply is null because the client is not looking for a reply. If it
  502. is null, don't bother to reply.
  503.  
  504. /* Disclaimer: All statments and opinions expressed are my own */
  505. /* Edmund K. Lai                                               */
  506. /* Apple Computer, MS37-UP                                     */
  507. /* 20525 Mariani Ave,                                          */
  508. /* Cupertino, CA 95014                                         */
  509. /* (408)974-6272                                               */
  510. zW@h9cOi
  511.  
  512. +++++++++++++++++++++++++++
  513.  
  514. From: johnl@spinner.cs.indiana.edu (John Lacey)
  515. Date: 26 Aug 92 20:17:25 GMT
  516. Organization: Computer Science, Indiana University
  517.  
  518. I am trying to get a simple app with Apple events going, but I can't
  519. even get by the Open Application event.
  520.  
  521. Problem #1: Using the code snippets from IM VI, the call to
  522. AEGetAttributePtr returns errAENotAEDesc.  The only thing I did was
  523. call AEProcessAppleEvent, and call AEGetAttributePtr first thing in my
  524. handler.
  525.  
  526. Problem #2: Is there any way to debug Apple event handlers in Think C
  527. 5.0?  If I run under Think C, AEProcessAppleEvent returns
  528. noOutstandingHLE.  No such problems with the built application.
  529.  
  530. What am I missing, and is there a good reference for this, or some
  531. example code?
  532.  
  533. - -- 
  534. John Lacey                   `Everything must end; meanwhile we
  535.                               must amuse ourselves.' --Voltaire
  536.  
  537. ---------------------------
  538.  
  539. From: dat@ukc.ac.uk (D.A.Turner)
  540. Subject: Porting code using fork() to the Mac
  541. Date: 5 Aug 92 13:00:24 GMT
  542. Organization: Computing Lab, University of Kent at Canterbury, UK.
  543.  
  544. I am interested in porting a medium size (c. 10k lines of source)  piece
  545. of  software developed in C under UNIX to the Mac environment.  The user
  546. interface will need to be rewritten, but there is another problem, which
  547. I wondered if anyone on this newsgroup can advise me about?
  548.  
  549. My C code uses *fork* quite a bit.  Does anyone know of a C  environment
  550. for  the Mac which supports fork() or provides some equivalent facility?
  551.  
  552. I don't need true concurrency - in all my  uses  of  fork()  the  parent
  553. waits  for the child to finish before resuming control.  (In other words
  554. I am using fork to provide the child with its own copy  of  state  space
  555. which it can write all over without disturbing the state of the parent.)
  556.  
  557. Is there a way to do this under the Mac O/S?  Rewriting my code  to  get
  558. rid of fork() would be very tedious and I would prefer to avoid that.
  559.  
  560. Thanks in advance for any help - I will summarise to the net  if  I  get
  561. any useful info.
  562.  
  563. David Turner
  564. University of Kent, England
  565.  
  566. +++++++++++++++++++++++++++
  567.  
  568. From: mikeb@sam.amgen.com (Michael Brennan)
  569. Date: 14 Aug 92 18:15:03 GMT
  570. Organization: Amgen
  571.  
  572. In article <503@owl.ukc.ac.uk> D.A.Turner, dat@ukc.ac.uk writes:
  573. >My C code uses *fork* quite a bit.  Does anyone know of a C  environment
  574. >for  the Mac which supports fork() or provides some equivalent facility?
  575.  
  576. Apple has released a "Threads" library on its developer CDs.  It's use is
  577. documented
  578. in issue 6 of Develop.  It has a calling syntax very similar to fork()
  579. and (from
  580. what I've been able to tell) appears to be quite robust.
  581.  
  582. The library itself is an MPW .o file with no source available, but I was
  583. able
  584. to convert it to a Think C library using oConv with no difficulty.  If
  585. you have
  586. access to Develop CDs or know anyone who does, I recommend getting ahold
  587. of the
  588. Threads library.
  589.  
  590. +++++++++++++++++++++++++++
  591.  
  592. From: orpheus@reed.edu (P. Hawthorne)
  593. Date: 16 Aug 92 00:10:18 GMT
  594. Organization: Reed College, Portland, OR
  595.  
  596.  
  597.   mikeb@sam.amgen.com, Michael Brennan, writes:
  598. : Apple has released a "Threads" library on its developer CDs. It's use is
  599. : documented in issue 6 of Develop. It has a calling syntax very similar to
  600. : fork() and (from what I've been able to tell) appears to be quite robust.
  601.  
  602.   If imitation is the sincerest form of flattery, then a failed attempt at
  603. imitation is the most telling. I, rather unsuccessfully, tried to take the
  604. same approach to a threading package for Object Pascal. It was like trying
  605. to walk on eggshells, and still make the perfect omelette.
  606.  
  607.   In the docs, there is some interesting discussion of a scheme for marking
  608. all unused code resources purgeable. The idea was to mark all code
  609. resources purgeable with the obvious exception of one resource, followed by
  610. a walk of the stack looking for anything resembling a return address, so
  611. that the relevant resources could be marked as non-purgeable.
  612.  
  613.   Has anyone given that a shot?
  614.  
  615.   Theus (orpheus@reed.edu)
  616.  
  617. +++++++++++++++++++++++++++
  618.  
  619. From: heksterb@cs.utwente.nl (Ben Hekster)
  620. Organization: University of Twente, Dept. of Computer Science
  621. Date: Sun, 16 Aug 1992 08:36:56 GMT
  622.  
  623. In article <1992Aug16.001018.26666@reed.edu> orpheus@reed.edu (P. Hawthorne) writes:
  624. >  In the docs, there is some interesting discussion of a scheme for marking
  625. >all unused code resources purgeable. The idea was to mark all code
  626. >resources purgeable with the obvious exception of one resource, followed by
  627. >a walk of the stack looking for anything resembling a return address, so
  628. >that the relevant resources could be marked as non-purgeable.
  629.  
  630. Hey, I do this!  And you say this scheme is actually documented
  631. somewhere?  It's exactly as you describe-- I keep all but a few 'CODE'
  632. segments purgeable, and install a grow zone function that scans the
  633. stack for addresses within these segments.  Any segment that
  634. isn't referenced from the stack is unloaded from the gz function.
  635. I know it sounds skanky but it works great!
  636.  
  637.     Obvious advantages:  I never ever have to worry about calling
  638. UnloadSeg again, so I can resegment my applications at any time without
  639. having to worry about whether I'm doing UnloadSeg calls in the right
  640. order and in the right place, and since I'm also not doing UnloadSeg
  641. in the main event loop on every CODE segment, there is zero overhead,
  642. if you have enough memory.
  643.  
  644.     Disadvantage:  Could fail under Pink.
  645.  
  646. - -- 
  647. Ben `Hackster' Hekster        | "He bides his time and thinks,
  648. heksterb@cs.utwente.nl        |  'There must be more to life than this!'"
  649.  
  650. +++++++++++++++++++++++++++
  651.  
  652. From: d88-jwa@dront.nada.kth.se (Jon W{tte)
  653. Organization: Royal Institute of Technology, Stockholm, Sweden
  654. Date: Sun, 16 Aug 1992 20:35:10 GMT
  655.  
  656. .edu> orpheus@reed.edu (P. Hawthorne) writes:
  657.  
  658.      In the docs, there is some interesting discussion of a scheme for marking
  659.    all unused code resources purgeable. The idea was to mark all code
  660.    resources purgeable with the obvious exception of one resource, followed by
  661.    a walk of the stack looking for anything resembling a return address, so
  662.    that the relevant resources could be marked as non-purgeable.
  663.  
  664.      Has anyone given that a shot?
  665.  
  666. Don't forget the registers ! And the stacks for all OTHER threads !
  667.  
  668. However, that's exactly how many garbage collection schemes work
  669. in various dynamic languages (such as LISP)
  670.  
  671. - -- 
  672. - - I have decided that it is not boxes but my lack of skill that's the problem.
  673. - - Traitor! This kind of attitude will get you nowhere around here. If you must
  674.   know, it's not your boxes that are the problem, it's your lack of a
  675.   sufficient number of boxes. Go out and buy something.
  676.  
  677. +++++++++++++++++++++++++++
  678.  
  679. From: heksterb@cs.utwente.nl (Ben Hekster)
  680. Date: 18 Aug 92 11:34:22 GMT
  681. Organization: University of Twente, Dept. of Computer Science
  682.  
  683.  
  684. Hi--
  685.  
  686. I had a couple of requests to post my CODE segment-unloading grow zone
  687. function, so here it is.
  688.  
  689.     As you can see, it's actually written in C++ (the Language of
  690. the Gods), not in Assembly.  I've taken this code out of my class
  691. library and extracted just (hopefully) all the relevant bits.  The
  692. conversion to C shouldn't be much of a problem.  Though I suppose some
  693. people may find it rather sparsely commented, that's the way I like
  694. it.  I prefer to think that it's self-documenting...
  695.  
  696.     I wouldn't necessarily mind rewriting it in 68000 if I thought
  697. it was worth it.  I haven't done any profiling on this code, so I'm not
  698. yet convinced that it would be, though I can see some nested loops in
  699. there and some possible `optimizations'.
  700.  
  701.     The reason why this doesn't really bother me is that the grow
  702. zone function doesn't get called often, and only when you are operating
  703. close to the limit of available memory.  One of the neat things about
  704. this scheme is that you will never get called nor will any segment ever
  705. be unloaded if you have enough memory available.  You only start paying
  706. a performance penalty when you are nearly out of memory, which seems
  707. reasonable.
  708.  
  709.     Remember, if you use this, you probably never have to call
  710. UnloadSeg again.  Just mark any segments that you want to allow to be
  711. purged as `purgeable'.  You may want to keep certain frequently used
  712. segments resident (i.e., preload and not purgeable).  You MUST NOT make
  713. the segment containing the grow zone function itself purgeable.
  714.  
  715.     Of course, if you can spot any problems with this, I'd be
  716. obliged if you'd let me know about them.  I can come up with some
  717. scenarios that might cause this to fail but they seem rather unlikely.
  718. In particular I can't find it documented anywhere whether I can
  719. actually count on A5 being valid in the gzProc.  I suppose that comes
  720. down to not making any Memory Manager calls without A5 being valid,
  721. but I don't think that's legal, so it looks like I'm safe.
  722.  
  723.     All I can say is that I and several beta testers have been
  724. using this code in an application of mine for several months now
  725. without any apparent problems.  Use at your own risk, &c. &c.
  726.  
  727. Enjoy!
  728.  
  729. P.S.:    View this code with an 8-character tab width.  Some of the lines
  730.     are longer than 80 characters, but I've let them wrap instead
  731.     of inserting line breaks or `fmt'ing the code
  732.  
  733. - ----- begins
  734.  
  735.  
  736. class TApplication {
  737. protected:
  738.     static pascal long GrowZone(Size cbNeeded);        // grow zone function
  739.     struct AddressRange { void *start, *end; };        // location of CODE in memory
  740.     short        fNumCODEResources;            // number of CODE resources
  741.     AddressRange    *fCODEAddresses;            // CODE addresses
  742.  
  743. public:
  744.     static TApplication *gApplication;            // last instantiated application
  745.     };
  746.  
  747.  
  748.  
  749. /*    TApplication
  750.     Application constructor
  751. */
  752. #pragma segment Initialization
  753. TApplication::TApplication()
  754. {
  755. fCODEAddresses = NULL;
  756.  
  757. // etc.
  758. ...
  759.  
  760. // install grow zone function
  761. fNumCODEResources = Count1Resources('CODE');
  762. fCODEAddresses = (AddressRange*) NewPtr(fNumCODEResources * sizeof(AddressRange)); mfault;
  763. if (fCODEAddresses)
  764.     SetGrowZone(&TApplication::GrowZone);
  765.  
  766. // leave a pointer for anyone to find me
  767. gApplication = this;
  768. }
  769.  
  770.  
  771. /*    ~TApplication
  772. */
  773. #pragma segment Termination
  774. TApplication::~TApplication()
  775. {
  776. if (fCODEAddresses) DisposPtr((Ptr) fCODEAddresses);
  777. }
  778.  
  779.  
  780. /*    CurrentA5
  781.     Returns the current value of A5
  782. */
  783. #pragma parameter __D0 CurrentA5
  784. void *CurrentA5() = 0x200d;                    // MOVE.L A5,D0
  785.  
  786.  
  787. /*    CurrentA7
  788.     Returns the current value of A7
  789. */
  790. #pragma parameter __D0 CurrentA7
  791. void *CurrentA7() = 0x200f;                    // MOVE.L A7,D0
  792.  
  793.  
  794. /*    GrowZone
  795.     Grow zone function
  796. */
  797. #pragma segment Main
  798. pascal long TApplication::GrowZone(
  799.     Size        cbNeeded                // bytes needed
  800.     )
  801. {
  802. (void) cbNeeded;                        // not used
  803. long unloadedSome = 0;
  804.  
  805. register AddressRange *codeAddress;
  806. register short i;
  807.  
  808. void *mask = StripAddress((Ptr) 0xffffffff);
  809.  
  810. // find all purgeable but locked CODE resources in memory
  811. register short numCODEResources = gApplication->fNumCODEResources;
  812. char saveResLoad = *(char*) 0x0a5e;                // from SysEqu.h
  813. SetResLoad(false);
  814.  
  815. for (i = 1, codeAddress = gApplication->fCODEAddresses; i <= numCODEResources; i++, codeAddress++) {
  816.     codeAddress->start = NULL;
  817.  
  818.     // is the resource in memory?
  819.     Handle codeH = Get1IndResource('CODE', i);
  820.     if (codeH && *codeH)
  821.         // is it a purgeable but locked resource?
  822.         if ((HGetState(codeH) & 0xe0) == 0xe0) {
  823.             // how big is it?
  824.             Size codeSize = GetHandleSize(codeH);
  825.             if (codeSize > 0) {
  826.                 // record the address range so it is eligible for purging
  827.                 codeAddress->start = (void*) ((long) *codeH & (long) mask);
  828.                 codeAddress->end = (char*) codeAddress->start + codeSize;
  829.                 }
  830.             }
  831.     }
  832.  
  833. if (saveResLoad) SetResLoad(true);
  834.  
  835. // examine the stack
  836. Zone &applZone = *ApplicZone();
  837. enum { CurStackBase = 0x0908 };
  838. void
  839.     *stackTop = CurrentA7(),                // stack to search
  840.     *stackBase = *((void**) CurStackBase),
  841.     *heapStart = &applZone.heapData,            // application zone data
  842.     *heapEnd = applZone.bkLim;
  843.  
  844. // search the stack for references to loaded segments
  845. enum { CurJTOffset = 0x0934 };
  846. for (register char *a7 = (char*) stackTop; a7 < stackBase; a7 += 2) {
  847.     // is the address on the stack within the application heap?
  848.     register void *stackData = (void*) (*(long*) a7 & (long) mask);
  849.     if (stackData >= heapStart && stackData < heapEnd)
  850.         // is it in any of the code segments?
  851.         for (i = 1, codeAddress = gApplication->fCODEAddresses; i < numCODEResources; i++, codeAddress++)
  852.             if (codeAddress->start && stackData >= codeAddress->start && stackData < codeAddress->end) {
  853.                 // exclude it from unloading
  854.                 codeAddress->start = NULL;
  855.                 break;
  856.                 }
  857.     }
  858.  
  859. // unload everything that wasn't referenced inside the stack
  860. for (i = 1, codeAddress = gApplication->fCODEAddresses; i < numCODEResources; i++, codeAddress++)
  861.     // may we unload it?
  862.     if (codeAddress->start) {
  863.         // ready to get it on!
  864.         UnloadSeg((char*) CurrentA5() +
  865.             (*(short*) CurJTOffset) +        // beginning of jump table
  866.             (*(short*) codeAddress->start) +    // segment's first entry in jump table
  867.             2                    // routine address
  868.             );
  869.         unloadedSome++;
  870.         }
  871.  
  872. return unloadedSome;
  873. }
  874.  
  875. - ----- ends
  876. - -- 
  877. Ben `Hackster' Hekster        | "He bides his time and thinks,
  878. heksterb@cs.utwente.nl        |  'There must be more to life than this!'"
  879.  
  880. ---------------------------
  881.  
  882. From: envy@reed.edu!envy.Reed.Edu!pcalahan (Patrick John Calahan)
  883. Subject: DESPERATE: switching pixmaps w/ SetPortPix
  884. Date: 6 Aug 92 16:12:10 GMT
  885. Organization: Reed College, Portland, OR
  886.  
  887. I still need a few lines of code which will do the following.
  888.  
  889. SetPortPix(myOffscreenPixMap);
  890.  
  891. blah blah draw
  892.  
  893. SetPortPix(backToNormalScreenPixMap);
  894.  
  895.  
  896. Has anyone done this, and if so, can you help me?  I think my problem is
  897. in getting back to the screen, but I've managed to thouroughly confuse  
  898. myself.
  899.     Any help is very much appreciated....
  900.  
  901. pcalahan@reed.edu
  902.  
  903. +++++++++++++++++++++++++++
  904.  
  905. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  906. Organization: Kalamazoo College
  907. Date: Fri, 7 Aug 1992 16:24:22 GMT
  908.  
  909. envy@reed.edu!envy.Reed.Edu!pcalahan (Patrick John Calahan) writes:
  910. >I still need a few lines of code which will do the following.
  911. >SetPortPix(myOffscreenPixMap);
  912. >blah blah draw
  913. >SetPortPix(backToNormalScreenPixMap);
  914.  
  915. Here's some code I wrote last year that did the trick for me.  I've
  916. made it into ThC version 5 code, but I'm not sure if I've ever tested it
  917. in exactly this form.  It should work anyway.  (Comments on this code
  918. are welcome!)
  919.  
  920. It's set up to use with an object, but it won't be too hard un-OOPify
  921. it.  The instance variables "itsPixMap" and "itsDIInfoHndl" you'll have
  922. to deal with yourself--in the old version, I passed a (PixMap*) to the
  923. startDrawing() routine, and it returned a diInfoHndl, which was the
  924. parameter passed to the stopDrawing() routine.
  925.  
  926.  
  927.     /* The "drawing-into" information struct. */
  928. typedef struct {
  929.     RGBColor    oldForeColor, oldBackColor;
  930.     GrafPtr        oldGrafPtr;
  931.     CGrafPort    theCGrafPort;
  932.     PixMapHandle    oldPortPMHndl, newPortPMHndl;
  933. } diInfo, *diInfoPtr, **diInfoHndl;
  934.  
  935. void CPixMap::startDrawingInto(void)
  936. {
  937. register diInfoPtr theDIInfoPtr;
  938. Boolean portWasOpened = FALSE;
  939. extern RGBColor gRGBBlack, gRGBWhite;
  940.  
  941. TRY {
  942.     
  943.     itsDIInfoHndl = (diInfoHndl) NewHandleClear( sizeof(diInfo) );
  944.     FailNIL(itsDIInfoHndl);
  945.     
  946.     MoveHHi((Handle) itsDIInfoHndl);
  947.     HLock((Handle) itsDIInfoHndl);
  948.     theDIInfoPtr = *itsDIInfoHndl;
  949.     
  950.     theDIInfoPtr->newPortPMHndl = (PixMapHandle) NewHandle( sizeof(PixMap) );
  951.     FailNIL(theDIInfoPtr->newPortPMHndl);
  952.     
  953.     GetForeColor(&theDIInfoPtr->oldForeColor);
  954.     GetBackColor(&theDIInfoPtr->oldBackColor);
  955.     GetPort(&theDIInfoPtr->oldGrafPtr);
  956.     
  957.     RGBForeColor(&gRGBBlack);
  958.     RGBBackColor(&gRGBWhite);
  959.     
  960.     OpenCPort(&theDIInfoPtr->theCGrafPort);
  961.     theDIInfoPtr->oldPortPMHndl = theDIInfoPtr->theCGrafPort.portPixMap;
  962.     **(theDIInfoPtr->newPortPMHndl) = this->itsPixMap;
  963.     theDIInfoPtr->theCGrafPort.portPixMap = theDIInfoPtr->newPortPMHndl;
  964.     portWasOpened = TRUE;
  965.     
  966.     SetPort((GrafPtr) &theDIInfoPtr->theCGrafPort);
  967.     
  968.     RGBForeColor(&gRGBBlack);
  969.     RGBBackColor(&gRGBWhite);
  970.     
  971.     HUnlock( (Handle) itsDIInfoHndl );
  972.  
  973. } CATCH {
  974.     
  975.     if (itsDIInfoHndl != NULL) {
  976.         if (portWasOpened) {
  977.             (**itsDIInfoHndl).theCGrafPort.portPixMap = (**itsDIInfoHndl).oldPortPMHndl;
  978.             CloseCPort(&(**itsDIInfoHndl).theCGrafPort);
  979.         }
  980.         if ((**itsDIInfoHndl).newPortPMHndl != NULL) {
  981.             DisposHandle( (Handle) (**itsDIInfoHndl).newPortPMHndl);
  982.         }
  983.         ForgetHandle(itsDIInfoHndl);
  984.     }
  985.     
  986. } ENDTRY;
  987. }
  988.  
  989.  
  990.  
  991. void CPixMap::stopDrawingInto(void)
  992. {
  993. diInfoPtr theDIInfoPtr;
  994.  
  995. HLock( (Handle) itsDIInfoHndl ); 
  996. theDIInfoPtr = *itsDIInfoHndl;
  997.  
  998. theDIInfoPtr->theCGrafPort.portPixMap = theDIInfoPtr->oldPortPMHndl;
  999. DisposHandle((Handle) theDIInfoPtr->newPortPMHndl);
  1000.  
  1001. CloseCPort(&theDIInfoPtr->theCGrafPort);
  1002.  
  1003. SetPort(theDIInfoPtr->oldGrafPtr);
  1004.  
  1005. RGBForeColor(&theDIInfoPtr->oldForeColor);
  1006. RGBBackColor(&theDIInfoPtr->oldBackColor);
  1007.  
  1008. ForgetHandle(itsDIInfoHndl);
  1009. }
  1010.  
  1011. - -- 
  1012.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  1013.  Sure, I subscribe to alt.sex, but I only read it for the articles...
  1014.  
  1015. +++++++++++++++++++++++++++
  1016.  
  1017. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  1018. Organization: Kalamazoo College
  1019. Date: Fri, 7 Aug 1992 17:19:09 GMT
  1020.  
  1021. There's at least one bug in my drawing-into-a-pixmap code:
  1022.  
  1023. >typedef struct {
  1024. >    ...
  1025. >    CGrafPort    theCGrafPort;
  1026. >    ...
  1027. >} diInfo, *diInfoPtr, **diInfoHndl;
  1028. >
  1029. >void CPixMap::startDrawingInto(void)
  1030. >{
  1031. >    ...
  1032. >    itsDIInfoHndl = (diInfoHndl) NewHandleClear( sizeof(diInfo) );
  1033. >    ...
  1034. >    HUnlock( (Handle) itsDIInfoHndl );
  1035. >    ...
  1036. >}
  1037.  
  1038. As we all know (blush) system data structures that you refer to with a
  1039. pointer typically must be non-relocatable.  This includes sound
  1040. channels, entries in the vertical blanking queue...and GrafPorts.
  1041.  
  1042. Take out the HUnlock at the end of startDrawingInto(), and you can
  1043. remove the HLock() at the start of stopDrawingInto() as well.  I threw
  1044. those in just before saving the article, thinking "hmmmm, I wonder why
  1045. I wanted to fragment memory like that?"  I should trust myself.  :-)
  1046. - -- 
  1047.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  1048.  He let the contents of the bottle do the thinking
  1049.  Can't shake the devil's hand and say you're only kidding            - TMBG
  1050.  
  1051. +++++++++++++++++++++++++++
  1052.  
  1053. From: ralph@merlin.anu.edu.au (Ralph Sutherland)
  1054. Organization: Mt. Stromlo and Siding Spring Observatories
  1055. Date: Thu, 13 Aug 92 07:00:30 GMT
  1056.  
  1057. Newsgroups: comp.sys.mac.programmer
  1058. Subject: Re: DESPERATE: switching pixmaps w/ SetPortPix
  1059. Summary: 
  1060. Expires: 
  1061. References: <m0mGARZ-0003hxC@envy.reed.edu>
  1062. Sender: 
  1063. Followup-To: 
  1064. Distribution: 
  1065. Organization: Mt. Stromlo and Siding Spring Observatories
  1066. Keywords: 
  1067.  
  1068.  In Article 21019 in comp.sys.mac.programmer:
  1069.  envy@reed.edu!envy.Reed.Edu!pcalahan (Patrick John Calahan) Wrote:
  1070.  
  1071. >I still need a few lines of code which will do the following.
  1072. >
  1073. >SetPortPix(myOffscreenPixMap);
  1074. >
  1075.  
  1076. I tried email but it bounced and there didn't ssem to be any further posts
  1077. So...
  1078.  
  1079.  
  1080. Is this pseudocode more useful? (excuse the tabs, and as always no guarantees):
  1081.  
  1082. variables:
  1083.  
  1084.     aPort:Grafptr;              {general purpose port vriable}
  1085.     Coffport:CGrafPtr;          {temp colour port}
  1086.     oldpix:PixMapHandle;        {save the old pixmap}
  1087.     offpix:PixMapHandle;        {offscreen pixmap, initialised elsewhere}
  1088.     pwidth,pheight:integer;     {offscreen size}
  1089.     r:rect;                     {offscreen size}
  1090.     anRGB:RGBColor;             {anRGB color!}
  1091.  
  1092. .
  1093. .
  1094. .
  1095.  
  1096.       GetPort(aPort);
  1097.  
  1098.       Coffport := nil; {paranoia}
  1099.  
  1100.       Coffport := cGrafPtr(NewPtr(sizeof(cGrafport)));
  1101.                                       {allocate temp port to hold pixmap}
  1102.  
  1103.       if (Coffport <> nil)) and (Memerror = Noerr) then {Always check....}
  1104.        begin
  1105.  
  1106.            OpenCPort(Coffport);             {init port}
  1107.            oldpix := Coffport^.portPixMap;  {save pixmap}
  1108.  
  1109.            setport(Grafptr(CoffPort));     {set port is a good idea}
  1110.            SetPortpix(offpix);             {use the offpix}
  1111.            portsize(pwidth, pheight);      {Size IS important}
  1112.            rectrgn(CoffPort^.VisRgn, r);   {needed if the pixmap is
  1113.                                             larger than the screen}
  1114.            cliprect(r);                    { just so we have a clip}
  1115.            with anRGB do
  1116.              begin
  1117.                   red := $C000;
  1118.                   green := $C000;
  1119.                   blue := $4000;
  1120.              end;
  1121.            RGBForeColor(anRGB);           {sort of yellow...}
  1122.            Fillrect(brect, black);        {solid colour}
  1123.  
  1124.            SetPortpix(oldpix);            {put back the pix,
  1125.                                           I don't know if you really
  1126.                                           have to restore the visrgn}
  1127.  
  1128.            setPort(aPort);                { move to another port
  1129.                                             *before* you dispose!}
  1130.  
  1131.            CloseCPort(CoffPort);          {dispose}
  1132.            disposPtr(Pointer(CoffPort));  {clean Up}
  1133.  
  1134.          end;
  1135. .
  1136. .
  1137. .
  1138.  
  1139. Hope this helps
  1140.  
  1141. cheers
  1142. Ralph Sutherland
  1143.  
  1144.  
  1145. - -- 
  1146. - ---- Ralph S. Sutherland      Mount Stromlo & Siding Spring Observatories.
  1147. - ---- ralph@madras.anu.edu.au  The Australian National University.
  1148. - ---- rss100@cscgpo.anu.edu.au --------------------------------------------
  1149.  
  1150. +++++++++++++++++++++++++++
  1151.  
  1152. From: ralph@mozart.anu.edu.au (Ralph Sutherland)
  1153. Organization: Mt. Stromlo and Siding Spring Observatories
  1154. Date: Thu, 13 Aug 92 06:49:45 GMT
  1155.  
  1156.  In Article 21019 in comp.sys.mac.programmer:
  1157.  envy@reed.edu!envy.Reed.Edu!pcalahan (Patrick John Calahan) Wrote:
  1158.  
  1159. >I still need a few lines of code which will do the following.
  1160. >
  1161. >SetPortPix(myOffscreenPixMap);
  1162. >
  1163.  
  1164. I tried email but it bounced and there didn't ssem to be any further posts
  1165. So...
  1166.  
  1167.  
  1168. Is this pseudocode more useful? (excuse the tabs, and as always no guarantees):
  1169.  
  1170. variables:
  1171.  
  1172.     aPort:Grafptr;              {general purpose port vriable}
  1173.     Coffport:CGrafPtr;          {temp colour port}
  1174.     oldpix:PixMapHandle;        {save the old pixmap}
  1175.     offpix:PixMapHandle;        {offscreen pixmap, initialised elsewhere}
  1176.     pwidth,pheight:integer;     {offscreen size}
  1177.     r:rect;                     {offscreen size}
  1178.     anRGB:RGBColor;             {anRGB color!}
  1179.  
  1180. .
  1181. .
  1182. .
  1183.  
  1184.       GetPort(aPort);
  1185.  
  1186.       Coffport := nil; {paranoia}
  1187.  
  1188.       Coffport := cGrafPtr(NewPtr(sizeof(cGrafport)));
  1189.                                       {allocate temp port to hold pixmap}
  1190.  
  1191.       if (Coffport <> nil)) and (Memerror = Noerr) then {Always check....}
  1192.        begin
  1193.  
  1194.            OpenCPort(Coffport);             {init port}
  1195.            oldpix := Coffport^.portPixMap;  {save pixmap}
  1196.  
  1197.            setport(Grafptr(CoffPort));     {set port is a good idea}
  1198.            SetPortpix(offpix);             {use the offpix}
  1199.            portsize(pwidth, pheight);      {Size IS important}
  1200.            rectrgn(CoffPort^.VisRgn, r);   {needed if the pixmap is
  1201.                                             larger than the screen}
  1202.            cliprect(r);                    { just so we have a clip}
  1203.            with anRGB do
  1204.              begin
  1205.                   red := $C000;
  1206.                   green := $C000;
  1207.                   blue := $4000;
  1208.              end;
  1209.            RGBForeColor(anRGB);           {sort of yellow...}
  1210.            Fillrect(brect, black);        {solid colour}
  1211.  
  1212.            SetPortpix(oldpix);            {put back the pix,
  1213.                                           I don't know if you really
  1214.                                           have to restore the visrgn}
  1215.  
  1216.            setPort(aPort);                { move to another port
  1217.                                             *before* you dispose!}
  1218.  
  1219.            CloseCPort(CoffPort);          {dispose}
  1220.            disposPtr(Pointer(CoffPort));  {clean Up}
  1221.  
  1222.          end;
  1223. .
  1224. .
  1225. .
  1226.  
  1227. Hope this helps
  1228.  
  1229. cheers
  1230. Ralph Sutherland
  1231.  
  1232.  
  1233. - -- 
  1234. - ---- Ralph S. Sutherland      Mount Stromlo & Siding Spring Observatories.
  1235. - ---- ralph@madras.anu.edu.au  The Australian National University.
  1236. - ---- rss100@cscgpo.anu.edu.au --------------------------------------------
  1237.  
  1238. ---------------------------
  1239.  
  1240. End of C.S.M.P. Digest
  1241. **********************
  1242.